package com.qc31.baselib.utils

import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.qc31.baselib.R
import com.qc31.baselib.custom.MToolbar

object ToolbarHelper {

    fun setToolbar(context: AppCompatActivity, titleId: Int) {
        setToolbar(context, context.getString(titleId))
    }

    fun setToolbar(context: AppCompatActivity, title: String) {
        context.findViewById<MToolbar>(R.id.mToolbar).setCenterTitle(title)
    }

    fun setMToolbar(context: AppCompatActivity, title: String): MToolbar {
        return context.findViewById<MToolbar>(R.id.mToolbar).apply {
            setCenterTitle(title)
        }
    }

    fun setToolbarView(context: AppCompatActivity, title: String, actionId: String): TextView {
        return context.findViewById<MToolbar>(R.id.mToolbar).setCenterTitle(title)
            .setActionTitle(actionId).getActionView()
    }

    fun setToolbar(
        context: AppCompatActivity,
        titleId: Int,
        actionId: Int,
        callback: MToolbar.IToolbarCallback
    ) {
        context.findViewById<MToolbar>(R.id.mToolbar)
            .setCenterTitle(titleId)
            .setActionTitle(actionId)
            .setCallBack(callback)
    }

    fun setToolbar(
        context: AppCompatActivity,
        title: String,
        actionId: String,
        callback: MToolbar.IToolbarCallback
    ) {
        context.findViewById<MToolbar>(R.id.mToolbar)
            .setCenterTitle(title)
            .setActionTitle(actionId)
            .setCallBack(callback)
    }

}